<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:v="urn:schemas-microsoft-com:vml">
  <head>
    <meta http-equiv="content-type" content="text/html; charset=UTF-8"/>
    <title>Google Maps JavaScript API Example: 	Reverse Geocoder</title>
    <script src="http://maps.google.com/maps?file=api&amp;v=2&amp;key=ABQIAAAAzr2EBOXUKnm_jVnk0OJI7xSosDVG8KKPE1-m51RBrvYughuyMxQ-i1QfUnH94QxWIa6N4U6MouMmBA" 
            type="text/javascript"></script>
    <script type="text/javascript">

    var map;
    var geocoder;
    var address;

    function initialize() {
      map = new GMap2(document.getElementById("map_canvas"));
      map.setCenter(new GLatLng(40.730885,-73.997383), 15);
      map.setUIToDefault();
	  map.setCenter(new GLatLng(39.9493, 116.3975), 13);
      GEvent.addListener(map, "click", getAddress);
      geocoder = new GClientGeocoder();
    }
    
    function getAddress(overlay, latlng) {
      if (latlng != null) {
        address = latlng;
        geocoder.getLocations(latlng, showAddress);
      }
    }

    function showAddress(response) {
      map.clearOverlays();
      if (!response || response.Status.code != 200) {
        alert("Status Code:" + response.Status.code);
      } else {
        place = response.Placemark[0];
        point = new GLatLng(place.Point.coordinates[1],
                            place.Point.coordinates[0]);
        marker = new GMarker(point);
        map.addOverlay(marker);
        marker.openInfoWindowHtml(
        '<b>orig latlng:</b>' + response.name + '<br/>' + 
        '<b>latlng:</b>' + place.Point.coordinates[1] + "," + place.Point.coordinates[0] + '<br>' +
        '<b>Status Code:</b>' + response.Status.code + '<br>' +
        '<b>Status Request:</b>' + response.Status.request + '<br>' +
        '<b>Address:</b>' + place.address + '<br>' +
        '<b>Accuracy:</b>' + place.AddressDetails.Accuracy + '<br>' +
        '<b>Country code:</b> ' + place.AddressDetails.Country.CountryNameCode);
		//alert(typeof(place));
		
		//alert(place.AddressDetails.Country.CountryName);
		//alert(place.AddressDetails.Country.Locality);
		//allPrpos(place.AddressDetails.Country);
		result=printObj(place.AddressDetails.Country);
		document.getElementById("result").innerHTML=result;
      }
	  
    }

	 function allPrpos(obj) { 
     // 用来保存所有的属性名称和值
     var props = "";
     // 开始遍历
     for(var p in obj){ 
        // 方法
         if(typeof(obj[p])=="function"){ 
             //obj[p]();
         }else{ 
             // p 为属性名称，obj[p]为对应属性的值
             props+= p + "=" + obj[p] + "\t";
         } 
     } 
     // 最后显示所有的属性
     alert(props);
 	}
 	
	function printObj(obj,line){
		result="<span>"+obj.toString()+"</span><br/>";
		for(var p in obj){
			if(typeof(p)!="function"){
				if(isStringOrNumber(obj[p])){
					result+=line+"<span>"+p+":"+obj[p]+"</span><br/>";
				}else{
					result+=printObj(obj[p],line+"-----");
				}
			}
		}
		return result;
	}
	
	function isStringOrNumber(obj){
		return typeof(obj)=="string"||typeof(obj)=="number";
	}
	

    </script>
  </head>

  <body onload="initialize()">
    <div id="map_canvas" style="width: 800px; height: 600px"></div>
	<div id="result"></div>
  </body>
</html>
